<!-- 排班管理 -->
<template>
  <div class="dashboard-container transport-task customer-list-box">
    <div class="app-container">
      <!-- 头部分 -->
      <el-card
        class="header"
        shadow="never"
      >
        <el-form
          ref="refFormData"
          :model="refFormData"
        >
          <el-row :gutter="60">

            <el-col :span="8">
              <el-form-item
                label="员工账号:"
                style="margin-bottom: 0px"
                label-width="110px"
              >
                <el-input
                  v-model="refFormData.id"
                  placeholder="请输入员工账号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="员工姓名:"
                style="margin-bottom: 0px"
                label-width="110px"
              >
                <el-input
                  v-model="refFormData.name"
                  placeholder="请输入员工姓名"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="工作模式:"
                style="margin-bottom: 20px"
                label-width="110px"
              >
                <el-select

                  v-model="refFormData.workPatternId"

                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="月份:"
                style="margin-bottom: 20px"
                label-width="110px"
              >

                <el-date-picker
                  v-model="value2"
                  type="month"
                  placeholder="选择月"
                  @change="changeTime"
                >
                </el-date-picker>

              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="所属机构:"
                style="margin-bottom: 20px"
                label-width="110px"
                prop="agencyId"
              >
                <treeselect
                  v-model="refFormData.agencyId"
                  :options="agencyOptions"
                  :normalizer="normalizer"
                  :searchable="true"
                  style="width: 100%"
                  placeholder="请选择所属机构"
                  no-options-text="暂无数据"
                  no-results-text="暂无数据"
                  @open="open"
                  @close="close"
                />

              </el-form-item>
            </el-col>
            <el-col
              :span="8"
              style="padding-left:50px"
            >
              <el-button
                type="warning"
                @click="handleFilter"
              >搜索</el-button>
              <el-button
                plain
                class="reset-btn"
                @click="resetForm"
              >重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <!-- 下部分 -->

      <el-card shadow="never">
        <el-button
          type="warning"
          style="margin-bottom:20px"
          @click="jumpToWorkArrangeSetting"
        >排班设置</el-button>
        <el-button
          type="danger"
          plain
          style="margin-bottom:20px"
        >绑定排班</el-button>

        <!-- 表格 -->
        <template>
          <el-table
            ref="multipleTable"
            :data="dataList"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              fixed
              type="selection"
              width="55"
            >
            </el-table-column>
            <el-table-column
              fixed
              label="员工账号"
              width="110"
              prop="employeeNumber"
            >

            </el-table-column>
            <el-table-column
              fixed
              prop="name"
              label="员工姓名"
              width="110"
            >
            </el-table-column>
            <el-table-column
              fixed
              prop="phone"
              label="员工电话"
              width="110"
            >
            </el-table-column>
            <el-table-column
              fixed
              prop="userType"
              label="员工角色"
              width="110"
            >
              <template v-slot="{row}">
                <span> {{ row.userType === 1 ? '员工' : row.userType === 2 ? '快递员' :row.userType===3 ? '司机' :'无' }}</span>
              </template>
            </el-table-column>
            <el-table-column
              fixed
              prop="workPatternName"
              label="当前工作模式"
              width="110"
            >
            </el-table-column>
            <!-- 11111111111111111111 -->
            <el-table-column
              v-for="index in length"
              :key="index"
              :label="index+ ''"
            >
              <template v-slot="{row}">
                <!-- <span>{{ row.workSchedules[index-1] }}</span> -->
                <span
                  v-if="!row.workPatternName"
                  class="rest"
                >无</span>
                <span
                  v-if="row.workPatternName && row.workSchedules[index-1]===true"
                  class="work"
                >上</span>
                <span
                  v-if="row.workPatternName && row.workSchedules[index-1]===false"
                  class="rest"
                >休</span>
              </template>
            </el-table-column>
          </el-table>

        </template>

        <el-row
          type="flex"
          justify="center"
        >
          <el-col :span="12">
            <div class="page">
              <el-pagination
                :current-page="currentPage4"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="Number(total)"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              >
              </el-pagination>
            </div>
          </el-col>

        </el-row>
      </el-card>

    </div>
  </div>
</template>
<script>
import { workManage, selectWorkHistoryList } from '@/api/transit'
// import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { agencyList } from '@/api/institutions'
export default {
  // components: { Treeselect },
  data() {
    return {

      options: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      refFormData: {
        id: '',
        name: '',
        work: '',
        mouth: '',
        organization: '',
        page: '',
        pageSize: '',
        workPatternId: '',
        employeeNumber: '',
        agencyId: ''
      },
      value: '',
      value2: '', // 月份
      currentPage4: 4,
      multipleSelection: [], // 定义checked表格
      dataList: [],
      total: null,
      // manageSearchFormData: {
      //   page: 1,
      //   pageSize: 10

      // },
      length: '',
      agencyOptions: [],
      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.children
        }
      }
    }
  },
  created() {
    this.getWorkManage()
    this.getList()
  },
  methods: {
    // 打开动画效果
    open() {
      this.$refs.arrow.style.transform = 'rotate(-180deg)'
    },
    close() {
      this.$refs.arrow.style.transform = 'rotate(0deg)'
    },
    // 重置
    resetForm() {
      this.$refs.refFormData.resetFields
      // this.searchkey = false
      this.refFormData = {
        id: '',
        name: '',
        work: '',
        mouth: '',
        organization: '',
        page: '',
        pageSize: '',
        workPatternId: '',
        employeeNumber: '',
        agencyId: ''
      }
      this.value2 = ''
      this.getWorkManage()
    },
    // 搜索信息
    handleFilter() {
      this.refFormData.page = 1
      this.getWorkManage(this.refFormData)
    },
    // 获取起始/目的地机构列表数据
    async getAgencyList() {
      const { data: res } = await agencyList()
      // 获取数据给options
      this.agencyOptions = JSON.parse(res)
    },
    // 获取工作模式
    async getList() {
      const { data } = await selectWorkHistoryList()
      console.log(...data['0'])
      console.log(...data['1'])
      this.options = [...data['0'], ...data['1']]
      console.log(this.options)
    },
    // 点击跳转
    jumpToWorkArrangeSetting() {
      this.$router.push({ name: 'workArrange-setting' })
    },
    // 获取数据
    async getWorkManage() {
      const params = { ...this.refFormData }
      // console.log(params)
      // if (params.status === 0) {
      //   delete params.status
      // }
      const { data } = await workManage(params)
      console.log(data.items[0].workSchedules.length)
      this.length = data.items[0].workSchedules.length
      this.total = data.counts
      // 获取数据给dataList
      this.dataList = data.items
      // console.log(this.dataList)
    },
    // 页码
    handleSizeChange(val) {
      this.refFormData.pageSize = val
      if (this.refFormData.page === 1) {
        this.getWorkManage(this.refFormData)
      }
    },
    handleCurrentChange(val) {
      this.refFormData.page = val
      this.getWorkManage()
    },
    // 表格获取假数据
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    changeTime(val) {
      console.log(val)
      const year = val.getFullYear()
      const month = (val.getMonth() + 1) >= 10 ? (val.getMonth() + 1) : '0' + (val.getMonth() + 1)
      this.refFormData.mouth = `${year}-${month}`
    }
  }
}

</script>

<style rel="stylesheet/scss" lang="scss" scoped>
/deep/ th.date{
  .cell{
    padding-left: 17px!important;
  }
}
.work {
  width: 24px;
  height: 24px;
  background: #ffeeeb;
  border: 1px solid #e15536;
  border-radius: 50%;
  text-align: center;
  color: #e15536;
  font-size: 13px;
}
.page{
height: 70px;
}
.history-name {
  width: auto !important;
  /deep/ .el-input__inner {
    width: 293px;
  }
}

.workArrange-manage-people-setting {
  /deep/ .el-dialog__body {
    padding: 30px 50px 10px 50px !important;
  }
  /deep/ .el-dialog__footer {
    padding-bottom: 40px;
  }
}
.header{
  margin-bottom: 20px;
padding-top: 20px;
}
.work-type {
  /deep/ .el-form-item__content {
    margin-left: 40px !important;
  }
  /deep/ .el-radio:first-child {
    margin-right: 80px !important;
  }
  /deep/.el-radio__label {
    font-weight: bold;
    color: #333333;
  }
}

.dialog-footer {
  .el-button {
    width: 89px;
    height: 36px;
    padding: 10px 20px;
  }
}

.rest {
  width: 24px;
  height: 24px;
  background: #eff3f8;
  border: 1px solid #d8dde3;
  border-radius: 50%;
  text-align: center;
  color: #20232a;
  font-size: 13px;
}
.page{
 margin-top: 10px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
}
.transport-task /deep/ .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}

// 下拉框
/deep/ .el-select {
  width: 100%;
}

/*定义滚动条轨道 内阴影+圆角*/
/deep/ .el-table--scrollable-x .el-table__body-wrapper {
  padding-bottom: 5px;
  margin-bottom: 5px;
  &::-webkit-scrollbar {
    height: 10px;
  }

  /*定义滑块 内阴影+圆角*/
  &::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: rgba(144, 147, 153, 0.3);
  }

  &::-webkit-scrollbar-track-piece {
    margin-right: 3px;
    margin-left: 3px;
  }
}
/deep/ .el-card{
  overflow: initial;
}

</style>

<style></style>
